#!/usr/bin/perl
#date_setting.cgi

require './mdmjobs-lib.pl';
&ReadParse();

&header($text{'date_detail'}, "", "index", 0, 1,undef,undef);
print "<form action=mdm_date.cgi method=post onsubmit='return checkselect(\"$text{'err_nomember'}\");'>\n";
print "<table class=mode1 border=0 cellspacing=0 cellpadding=0>\n";
print "<tr><td>\n";
local $grpinfo=&foreign_call("mdmgroups","get_groupinfo");
local %grpinfo=%$grpinfo;
local @group = split (/,/,$grpinfo{'[group]'});
&select_members(\@group);	
print "</td></tr>\n";

print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<hr align=left width=550>\n";
print "<tr><td><table class=mode1 border=0 cellspacing=0 cellpadding=2>\n";
print "<h4>$text{'index_setdate'}</h4>\n";
print "$text{'index_setdatemsg'}<p>\n";
print "</table></td></tr>\n";

print "<table class=mode1 cellspacing=2 cellpadding=4>\n";
print "<tr><td width=40><b>$text{'date'}</b></td>\n";

$rawyear = `date +%Y`;
chop($rawyear);
print "<td><select name=year>\n";
for ($i = 1970; $i < 2039; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i eq $rawyear)?"selected":"";
}
print "</select>$text{'year'}</td>\n";

$rawmonth = `date +%m`;
chop($rawmonth);
print "<td><select name=month>\n";
for ($i = 1; $i < 13; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawmonth )?"selected":"";
}
print "</select>$text{'month'}</td>\n";

$rawday = `date +%e`;
print "<td><select name=day>\n";
for ($i = 1; $i < 32; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawday)?"selected":"";
}
print "</select>$text{'day'}</td></tr>\n";


print "<tr><td><b>$text{'time'}</b></td>\n";

$rawhour = `date +%H`;
chop($rawhour);
print "<td><select name=hour>\n";
for ($i = 0; $i < 24; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawhour)?"selected":"";
}
print "</select>$text{'hour'}</td>\n";

$rawmin = `date +%M`;
chop($rawmin);
print "<td><select name=minute>\n";
for ($i = 0; $i < 60; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawmin)?"selected":"";
}
print "</select>$text{'minute'}</td>\n";

$rawsec = `date +%S`;
chop($rawsec);
print "<td><select name=second>\n";
for ($i = 0; $i < 60; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawsec)?"selected":"";
}
print "</select>$text{'second'}</td></tr>\n";

=no timezone

print "<tr><td><b>$text{'zone'}</b></td>\n";
print "<td colspan=3><select name=zone>\n";
$zonelink = readlink($config{'zonelink'});
print "<option value=''>$text{'noselect'}\n";
my @zones;
open(TAB, $config{'zonetab'});
while(<TAB>) {
	s/\r|\n//g;
	s/#.*$//;
	if (/^(\S+)\s+(\S+)\s+(\S+)\s*(.*)/)
	{
#		printf "<option %s value='$3'>%s\n", ("$config{'zonedir'}/$3" eq $zonelink)?"selected":"", $3;
		push(@zones, $3);
	}
}
close(TAB);
@zones = sort {lc($a) cmp lc($b)} @zones;
for ($i = 0 ; $i < @zones; $i++)
{
	printf "<option %s value='$zones[$i]'>%s\n", ("$config{'zonedir'}/$zones[$i]" eq $zonelink)?"selected":"", $zones[$i];	
}	
print "</select></td></tr>\n";
=cut

print "</table></tr>\n";

print "<tr><td><input type=submit class=button1 value=\"$text{'index_submit'}\"></td></tr>\n";
print "</table></td></tr>\n";
print "</table></form>\n";
print <<EOF;
<script>
function checkselect(alertmessg1)
{
	if(document.forms[0].memberlist.options.length == 0){
		alert(alertmessg1);
		return false;
	}
	
	if(!confirm("$text{'msg_confirm'}")){
                return false;
        }
	
	if(document.forms[0].listinput.value == ""){
		if(document.forms[0].memberlist.options.length > 0){
			document.forms[0].listinput.value = document.forms[0].memberlist.options[0].text;
		}else{
			document.forms[0].listinput.value = "";
		}	

		for(i = 1; i < document.forms[0].memberlist.options.length; i++){
			document.forms[0].listinput.value += "," + document.forms[0].memberlist.options[i].text;
		}
	}
}
</script>
EOF

&footer("index.cgi", $text{'index_title'});
1;
